<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function axios (options) {
            // 创建一个promise对象
            return new Promise((resolve,reject) => {
                // 创建一个xhr对象
                const xhr = new XMLHttpRequest()
                // 设置请求方式和地址
                xhr.open(options.method, options.url) 
                // 设置请求体
                xhr.send(null)

                // 监视请求
                xhr.onreadystatechange = function() {
                    if(xhr.readyState === 4) {
                        if(xhr.status === 200) {
                            console.log('请求成功')
                            resolve(JSON.parse(xhr.responseText))
                        } else {
                            console.log('请求失败')
                            reject(new Error(xhr.responseText))
                        }
                    }
                }
            })
        }

        axios({
            method: 'get',
            url: 'http://localhost:3000/heroes/10013'
        }).then(res => {
            console.log(res)
            console.log('成功')
        })
    </script>
</body>
</html>